<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@ include file="/include/taglibs.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false" %>
<head>
	<link rel="stylesheet" href="${ctx}/assets/admin/LingUI/css/ui.jqgrid.css" />
	<%@ include file="/include/openstyles.jsp"%>
	<script src="${ctx}/assets/admin/pagejs/common.js"></script>
</head>

<body>
	<div class="row">
		<div class="col-xs-12">
			<table id="position_list_table" class="grid-table"></table>
		</div>
	</div>
</body>
<script type="text/javascript">
	var scripts = [null,
		"${ctx}/assets/admin/LingUI/js/jqGrid/jquery.jqGrid.js",
		"${ctx}/assets/admin/LingUI/js/jqGrid/i18n/grid.locale-cn.js",
		"${ctx}/assets/admin/LingUI/js/control.js",
		"${ctx}/assets/admin/LingUI/js/jsutil/js/jquery.filterSearch.js",   //筛选搜索
		null];
	var _grid_id = "#position_list_table";	//表格 选择器
	ace.load_ajax_scripts(scripts, function() {

		jQuery(_grid_id).jqGrid({
			mtype : "POST",
			url: "${ctx}/${frameworkPath}/position/${param.positionId}/role/datagrid",
			colNames:['角色编号','角色名称','选中状态'],
			colModel:[
				{name:'id',index:'id', width:0,  editable: false},
				{name:'name',index:'name', width:0,  editable: false},
				{name:'checked',index:'checked', width:0,  editable: false,hidden:true}
			],
			afterInsertRow:function(id,row){
				if(row.checked){
					jQuery(_grid_id).jqGrid('setSelection',id);
				}
			},
			caption:'角色列表'
		});
	});

	function submit(){
		var retObj =new Object();
		var rows = $(_grid_id).jqGrid('getGridParam', 'selarrrow');
		var idArray = new Array();
		for ( var i = 0; i < rows.length; i++) {
			idArray.push(rows[i]);
		}
		$.ajax({
			type : 'POST',
			url : '${ctx}/${frameworkPath}/position/${param.positionId}/role',
			traditional : true,
			async :false,
			dataType:'json',
			data : {'ids' : idArray},
			success : function(data) {
				if (data.success) {
					retObj.text ="保存成功！";
					retObj.state = true;
				} else {
					retObj.text = text;
					retObj.state =false;
				}
			},
			error : function(XmlHttpRequest, textStatus, errorThrown) {
				lui.fail("操作出现错误");
			}
		});
		return retObj;
	}
</script>